home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Example1.c
- Contains: Compression of PICT Files
- Written by: DTS and QT Engineering
- Copyright: © 1992-1994 by Apple Computer, Inc., all rights reserved.
- Change History (most recent first):
- <1> 12/4/94 khs changed the format of the file to the new look and feel
- To Do:
- */
-
-
- // The following sample code shows the simplest case of asking the user for a picture file
- // to be compressed, asking them for some compression settings, then compressing the
- // picture file with those settings and quitting.
- //
- // This is only a marginally practical example. A real application would not want to use
- // the various calls exactly in the manner described below. It is more useful as a
- // demonstration of how the calls behave in different situations.
-
-
- // INCLUDE FILES
- #include <menus.h>
- #include <fonts.h>
- #include <osevents.h>
- #include <components.h>
- #include <quicktimecomponents.h>
-
-
- // FUNCTION PROTOTYPES
- void Example1(void);
-
-
- // FUNCTIONS
- void Example1(void)
- {
- ComponentResult result;
- Point where;
- ComponentInstance ci;
- short sref;
- SFTypeList typeList;
- SFReply reply;
-
- // Tell SFGetFilePreview to center on the best monitor.
-
- where.h = where.v = -2;
-
- // Show only 'PICT' files in the file list.
-
- typeList[0] = 'PICT';
-
- // Ask user to select PICT file to be compressed.
-
- SFGetFilePreview(where, "\p", nil, 1, typeList, nil, &reply);
- if (reply.good)
- {
-
- // If they selected a file, open that file.
-
- result = FSOpen(reply.fName, reply.vRefNum, &sref);
- if (!result)
- {
-
- // Open the Standard Compression Dialog component.
-
- ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
- if (ci)
- {
-
- // If the component opened successfully, set the picture file to
- // be the test image shown in the dialog. Passing nil for srcRect
- // means use the entire image. Passing 0 for testFlags means
- // to use the default system method of displaying the test image
- // which is currently a combination of cropping and scaling.
-
- SCSetTestImagePictFile(ci, sref, nil, 0);
-
- // We don't need to explicitly set default compression settings
- // in this example. SCCompressPictureFile will see that no
- // defaults have been set since the component has been open
- // and call SCDefaultPictFileSettings with the test image for you.
- // If other defaults did exist, the following call would need to be made:
- //
- // result = SCDefaultPictFileSettings(ci,sref);
-
- // Again, because no settings exist yet, SCCompressPictureFile will
- // call SCRequestImageSettings automatically to get settings from
- // the user. If other settings had been made previously, the following
- // call would have to be made to explicitly ask the user for settings:
- //
- // result = SCRequestImageSettings(ci);
-
- // Compress the picture file with the settings chosen by the user.
- // The settings include any custom color table found in the source
- // picture if still appropriate for the depth chosen by the user.
- //
- // Note that we are able to pass the source file ref for both the
- // source and destination picture files. In this case, the picture
- // file will be compressed in place. It would probably be better to
- // ask the user for a name to save the compressed file as, rather than
- // compressing it in place.
- //
- // Also note that the result code returned could include scUserCancelled.
-
- result = SCCompressPictureFile(ci, sref, sref);
-
- // Close the Standard Compression Dialog component.
-
- CloseComponent(ci);
- }
-
- // Close the source picture file.
-
- FSClose(sref);
- }
- }
- }
-
-
- // MAIN FUNCTION
- void main(void)
- {
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- InitDialogs(nil);
- InitCursor();
- MaxApplZone();
-
- Example1();
- }
-
-
-